TARGET = gsh
OBJDIR = obj

SRC = main.cpp

OBJ = $(SRC:%.cpp=%.o)

CPPSTD  = -std=c++0x
CPPDEFS = 
LIBDEFS =  -lstdc++ -lsanctioned -ldl
#LIBDEFS = -lcurses -lstdc++
LIBDEFS += -lmysqlpp -lmysqlclient
LIBDIRS = ../lib /usr/local/lib
INCDEFS = 
INCDIRS = ../lib /usr/include/mysql /usr/local/include/mysql++
DEBUG   = stabs
OPT	= s

CPPFLAGS = -g$(DEBUG)
CPPFLAGS += $(CPPDEFS)
CPPFLAGS += -O$(OPT)
#CPPFLAGS += -x c++
#CPPFLAGS += -fshort-enums
CPPFLAGS += -funsigned-bitfields
#CPPFLAGS += -fno-exceptions #can't use this with mysql++
#CPPFLAGS += -fno-rtti #can't use this with mysql++ or mysql c++ connector
#CPPFLAGS += --ansi --pedantic
CPPFLAGS += -Wall
#CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=%.lst)

#LDDFLAGS = -Wl,-Map=$(TARGET).map,--cref
#LDDFLAGS += -Wl,-relax,--gc-sections

LDDFLAGS = $(patsubst %,-L%,$(LIBDIRS))
LDDFLAGS += $(LIBDEFS)

#LDDFLAGS += $(patsubst %,-R%,$(LIBDIRS))
INCFLAGS += $(patsubst %,-I%,$(INCDIRS))

DEPFLAGS = -MMD -MP -MF .dep/$(@F).d

ALLCPPFLAGS = $(INCFLAGS) $(CPPFLAGS) $(DEPFLAGS)

CC = g++
NM = nm
RM = rm -rf
COCO = Coco
LD = /bin/ld

all: begin $(TARGET) end

begin:
	@echo
	@echo "--------[ Building Government Sanctioned Command Shell ]---------"

end:
	@echo
	@echo "************** FINISHED GSH **************"


.SECONDARY : $(TARGET)
.PRECIOUS : $(OBJ)
$(TARGET): $(OBJ)
	$(CC) $(OBJ) --output $@ $(LDDFLAGS)

%.o: %.cpp
	$(CC) -c $(ALLCPPFLAGS) $(CPPSTD) $< -o $@

clean:
	@echo
	@echo "--------[ Cleaning gsh Directory ]----------"
	$(RM) $(TARGET)
	$(RM) $(TARGET).map
	$(RM) *.lst
	$(RM) $(OBJ)
	$(RM) .dep

# Create object files directory
$(shell mkdir $(OBJDIR) 2>/dev/null)

-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)

